clear all 

use Data_MadagascarIE_Open.dta, clear 

// Table B. Attrition analysis
global xlist letter_b word_b para_b story_b math_std_b_attrit student_age_b student_sex_b repeat_b num_stu_tot num_classroom sch_fac_water sch_fac_toilet sch_fac_library sch_fac_kitchen hm_incharge ratio_fonction i.strataFE

eststo clear
eststo All: reg attrit treat $xlist i.Grade Multi_grade_T3_grade3 Multi_grade_T4_grade4 Multi_grade_T5_grade5, cl(School_Code)
eststo T3: reg attrit treat $xlist Multi_grade_T3 if Grade==3, cl(School_Code)
eststo T4: reg attrit treat $xlist Multi_grade_T4 if Grade==4, cl(School_Code)
eststo T5: reg attrit treat $xlist Multi_grade_T5 if Grade==5, cl(School_Code)
esttab * using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps nodep b(3) se(3) label replace

* Number of attitors among the participants of the baseline survey by grade 
tabstat attrit, by(Grade) s(count sum)

* Drop attritors
drop if attrit==1

* Prepare variables for Athey and Imbens' specification 
run Vars_AtheyImbens.do
 

// Table C-1. Impact on math test scores by cognitive skills
* All sample
global xlist_reg student_age_b_dota-Treat_grade5_dota

eststo clear
eststo: reg math_Q1_40_std treat *math_Q1_40_std_b_dota i.strataFE $xlist_reg, cl(School_Code)
eststo: reg math_Q41_44_std treat *math_Q41_44_std_b_dota i.strataFE $xlist_reg, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace

* Grade 3
eststo clear
global xlist_reg student_age_b_dot3-Treat_sch_fac_kitchen_dot3
eststo: reg math_Q1_40_std treat *math_Q1_40_std_b_dot3 i.strataFE $xlist_reg if Grade==3, cl(School_Code)
eststo: reg math_Q41_44_std treat *math_Q41_44_std_b_dot3 i.strataFE $xlist_reg if Grade==3, cl(School_Code)

global xlist_reg student_age_b_dot4-Treat_sch_fac_kitchen_dot4
eststo: reg math_Q1_40_std treat *math_Q1_40_std_b_dot4 i.strataFE $xlist_reg if Grade==4, cl(School_Code)
eststo: reg math_Q41_44_std treat *math_Q41_44_std_b_dot4 i.strataFE $xlist_reg if Grade==4, cl(School_Code)

* Grade 5
global xlist_reg student_age_b_dot5-Treat_sch_fac_kitchen_dot5
eststo: reg math_Q1_40_std treat *math_Q1_40_std_b_dot5 i.strataFE $xlist_reg if Grade==5, cl(School_Code)
eststo: reg math_Q41_44_std treat *math_Q41_44_std_b_dot5 i.strataFE $xlist_reg if Grade==5, cl(School_Code)

esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace


// Table C-2. Impact on math test scores (sub-sample analysis by gender)
eststo clear
global xlist_reg student_age_b_dotm-Treat_grade5_dotm
eststo: reg irt_score_std treat *irt_score_std_b_dotm i.strataFE $xlist_reg if student_sex_b==0, cl(School_Code)

global xlist_reg student_age_b_dotf-Treat_grade5_dotf
eststo: reg irt_score_std treat *irt_score_std_b_dotf i.strataFE $xlist_reg if student_sex_b==1, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace


// Table C-3. Impact on basic reading (sub-sample analysis by the baseline level)
* Baseline literacy level: Beginner 
global xlist_reg2 student_age_b_dL1-Treat_grade5_dL1

eststo clear
eststo: reg beginner treat i.strataFE $xlist_reg2 if beginner_b==1, cl(School_Code)
eststo: reg letter treat i.strataFE $xlist_reg2 if beginner_b==1, cl(School_Code)
eststo: reg word treat i.strataFE $xlist_reg2 if beginner_b==1, cl(School_Code)
eststo: reg para treat i.strataFE $xlist_reg2 if beginner_b==1, cl(School_Code)
eststo: reg story treat i.strataFE $xlist_reg2 if beginner_b==1, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace

* Baseline literacy level: Letter 
global xlist_reg2 student_age_b_dL2-Treat_grade5_dL2

eststo clear
eststo: reg beginner treat i.strataFE $xlist_reg2 if letter_b==1, cl(School_Code)
eststo: reg letter treat i.strataFE $xlist_reg2 if letter_b==1, cl(School_Code)
eststo: reg word treat i.strataFE $xlist_reg2 if letter_b==1, cl(School_Code)
eststo: reg para treat i.strataFE $xlist_reg2 if letter_b==1, cl(School_Code)
eststo: reg story treat i.strataFE $xlist_reg2 if letter_b==1, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace

* Baseline literacy level: Word 
global xlist_reg2 student_age_b_dL3-Treat_grade5_dL3

eststo clear
eststo: reg letter treat i.strataFE $xlist_reg2 if word_b==1, cl(School_Code)
eststo: reg word treat i.strataFE $xlist_reg2 if word_b==1, cl(School_Code)
eststo: reg para treat i.strataFE $xlist_reg2 if word_b==1, cl(School_Code)
eststo: reg story treat i.strataFE $xlist_reg2 if word_b==1, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace

* Baseline literacy level: Paragraph 
global xlist_reg2 student_age_b_dL4-Treat_grade5_dL4

eststo clear
eststo: reg word treat i.strataFE $xlist_reg2 if para_b==1, cl(School_Code)
eststo: reg para treat i.strataFE $xlist_reg2 if para_b==1, cl(School_Code)
eststo: reg story treat i.strataFE $xlist_reg2 if para_b==1, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace

* Baseline literacy level: Story 
global xlist_reg2 student_age_b_dL5-Treat_grade5_dL5

eststo clear
eststo: reg para treat i.strataFE $xlist_reg2 if story_b==1, cl(School_Code)
eststo: reg story treat i.strataFE $xlist_reg2 if story_b==1, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace


// Table C-4. Impact on basic reading (sub-sample analysis by gender)
* Female students
global xlist_reg letter_b_dotm-Treat_story_b_dotm
global xlist_reg2 student_age_b_dotf-Treat_grade5_dotf

eststo clear
eststo: reg beginner treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==1, cl(School_Code)
eststo: reg letter treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==1, cl(School_Code)
eststo: reg word treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==1, cl(School_Code)
eststo: reg para treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==1, cl(School_Code)
eststo: reg story treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==1, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace

* Male students
global xlist_reg letter_b_dotm-Treat_story_b_dotm
global xlist_reg2 student_age_b_dotm-Treat_grade5_dotm

eststo clear
eststo: reg beginner treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==0, cl(School_Code)
eststo: reg letter treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==0, cl(School_Code)
eststo: reg word treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==0, cl(School_Code)
eststo: reg para treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==0, cl(School_Code)
eststo: reg story treat i.strataFE $xlist_reg $xlist_reg2 if student_sex_b==0, cl(School_Code)
esttab using temp.csv, star(* 0.1 ** 0.05 *** 0.01) drop(*.strataFE) nogaps depvars b(3) se(3) replace

** Average in the control group
tabstat beginner_b letter_b word_b para_b story_b if treat==0, by(student_sex_b)

